package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.mapper.TbRegionMapper;
import com.heima.pojo.TbRegion;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.RegionVo;
import com.heima.service.ITbRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 运营区域 服务实现类
 * </p>
 *
 * @author nan
 * @since 2024-06-07
 */
@Service
public class TbRegionServiceImpl extends ServiceImpl<TbRegionMapper, TbRegion> implements ITbRegionService {

    @Autowired
    private TbRegionMapper regionMapper;

    /**
     * 区域搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public PageResponse<RegionVo> getByPage(Integer pageIndex, Integer pageSize, String name) {
        Page<TbRegion> page = new Page<>(pageIndex,pageSize);

        Page<RegionVo> tbPartnerPage =regionMapper.getByPage(page, name);
        PageResponse<RegionVo> pageResponse = new PageResponse<>();
        pageResponse.setPageIndex(tbPartnerPage.getCurrent());
        pageResponse.setPageSize(tbPartnerPage.getSize());
        pageResponse.setTotalPage(tbPartnerPage.getPages());
        pageResponse.setTotalCount(tbPartnerPage.getTotal());
        pageResponse.setCurrentPageRecords(List.copyOf(tbPartnerPage.getRecords()));
        return pageResponse;
    }
}
